package com.granada.service.ping;


import com.granada.behaviour.base.PermissionBehavior;
import com.granada.behaviour.base.RolePermissionBehavior;
import com.granada.behaviour.interfaces.RoleBehavior;
import com.granada.entity.Ao;
import com.granada.entity.SysRoleCompound;
import com.granada.exception.BusinessException;
import com.granada.exception.code.BaseResponseCode;
import com.granada.model.common.Role;
import com.granada.service.base.RoleService;
import com.granada.vo.resp.PermissionRespNode;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RoleWithPingService extends RoleService implements RoleBehavior {


    public RoleWithPingService(Role roleModel, com.granada.behaviour.base.RoleBehavior roleBehavior, PermissionBehavior permissionBehavior, RolePermissionBehavior rolePermissionBehavior, Ao ao) {
        super(roleModel, roleBehavior, permissionBehavior, rolePermissionBehavior, ao);
    }



    @Override
    public SysRoleCompound getOne() throws Exception {
        SysRoleCompound one = (SysRoleCompound) this.roleModel.getOne();
        if(one==null){
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        List<PermissionRespNode> permissionRespNodes = permissionBehavior.selectAllByTree();
        Set<Long> checkList = new HashSet<>(rolePermissionBehavior.getPermissionIdsByRoleId(one.getId()));
        roleBehavior.setheckced(permissionRespNodes,checkList);
        one.setPermissionRespNodes(permissionRespNodes);
        return  one;
    }


}
